<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  	<link rel="stylesheet" type="text/css" href="assets/css/lightbox.css" />
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>공지사항 조회/수정</h2>
		</div>

		<form id="updateNotice" class="form-horizontal" role="form" method="post" action="updateNotice.do" enctype="multipart/form-data">
			<fieldset>
			
				<input type="hidden" name="idAdminBoard" value="${cmd.idAdminBoard}"/>
			
				<div class="form-group">
					<label for="boardTitle" class="col-md-2 control-label">제목</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="boardTitle" value="${cmd.boardTitle}"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="boardText" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea id="boardText" name="boardText" class="form-control" rows="10">${cmd.boardText}</textarea>
					</div>
				</div>
				
				<div class="form-group">
					<label for="noticeImg" class="col-md-2 control-label">이미지</label>
					<div class="col-md-10">
					
						<c:choose>
							<c:when test="${image == null}">
								<p class="form-control-static">등록된 이미지가 존재하지 않습니다.</p>
								<input type="file" class="form-control" name="newImg"/>
							</c:when>
							<c:otherwise>
								<div class="row">
									<div class="col-md-4">
										<p class="form-control-static">
											<a href="download.jsp?${image}" data-lightbox="roadtrip" title="${cmd.boardTitle}">
												<img src="download.jsp?${image}" class="img-thumbnail img-responsive"/>
											</a>
										</p>
									</div>
									<div class="col-md-8">
										<br/>
										<ul>
											<li>항번: ${image.idAttacheFile}</li>
											<li>원본 파일 이름: ${image.fileOrgName}</li>
											<li>파일 크기: ${image.fileSize}byte</li>
											<li>업로드된 파일 이름: ${image.fileSaveName}</li>
											<li>업로드된 폴더 경로: ${image.fileDir}</li>
											<li>파일 타입: ${image.fileType}</li>
										</ul>
										&nbsp;&nbsp;&nbsp;&nbsp;
										<label class="checkbox-inline"><input type="checkbox" name="imgDelete" value="${image.fileSaveName}">
										(삭제) ${image.fileOrgName}</label>
										<button type="button" class="btn btn-sm" id="imgEdit">변경</button>
										<br/><br/>
										<div id="imgDiv"><input type="file" class="form-control" name="editImg"/></div>
									</div>
								</div>
							</c:otherwise>
						</c:choose>
						
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<script src="assets/js/lightbox-2.6.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#imgDiv").hide();
			
			$("#updateNotice").submit(function() {
				
				if (!$("input[name='boardTitle']").val().isValue()) {
					alert("제목을 입력하세요.");
					$("input[name='boardTitle']").focus();
					return false;
				}
				
				if (!$("textarea[name='boardText']").val().isValue()) {
					alert("내용을 입력하세요.");
					$("textarea[name='boardText']").focus();
					return false;
				}
				
				if (!confirm("정말 수정하시겠습니까?")) {
					return false;
				}
				
			});
			
			$("#imgEdit").click(function() {
				$("input[name='imgDelete']:checkbox").attr("checked", false);
				$("input[name='editImg']").replaceWith($("input[name='editImg']").clone(true));
				$("#imgDiv").toggle();
			});
			
			$("input[name='imgDelete']").click(function() {
				$("input[name='editImg']").replaceWith($("input[name='editImg']").clone(true));
				$("#imgDiv").hide();
			});
		});
	</script>
  </body>
</html>